blob: b95ef8aefc1e1f19a92d27ab1342847006c26022 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
<script lang="ts" context="module">
import type { Load } from '@sveltejs/kit'
import { fetchApi } from '$lib/api'
export const load: Load = async ({ params, fetch }) => {
const player: string = params.player
const data = await fetchApi(`player/${player}?customization=true`, fetch).then(r => r.json())
if (!data.player) {
return {
status: 404,
error: 'Unknown player',
}
}
if (data.player.username !== player) {
return {
redirect: `/player/${data.player.username}`,
status: 302,
} as any
}
return {
props: {
data,
},
}
}
</script>
<script lang="ts">
import type { CleanPlayer, CleanProfile, CleanUser } from '$lib/APITypes'
import BackgroundImage from '$lib/BackgroundImage.svelte'
import Username from '$lib/minecraft/Username.svelte'
import Header from '$lib/Header.svelte'
import Head from '$lib/Head.svelte'
import { chooseDefaultBackground } from '$lib/backgrounds'
import Emoji from '$lib/Emoji.svelte'
import { MODE_EMOJIS, DEFAULT_MODE_EMOJI } from '$lib/profile'
import Tooltip from '$lib/Tooltip.svelte'
import { cleanId } from '$lib/utils'
import { navigating } from '$app/stores'
export let data: CleanUser & { player: CleanPlayer }
let activeProfile: CleanProfile | null = null
let activeProfileLastSave: number = 0
let isActiveProfileOnline: boolean
function updateActiveProfile() {
if (data.profiles)
for (const profile of data.profiles) {
if (profile.members)
for (const member of profile.members) {
if (member.uuid === data.player?.uuid && member.lastSave > activeProfileLastSave) {
activeProfile = profile
activeProfileLastSave = member.lastSave
}
}
}
isActiveProfileOnline = Date.now() - 60 < activeProfileLastSave
}
let backgroundUrl: string | null
$: {
$navigating
backgroundUrl = data.customization?.backgroundUrl ?? chooseDefaultBackground(data.player.uuid)
updateActiveProfile()
}
</script>
{#if backgroundUrl}
<BackgroundImage url={backgroundUrl} />
{/if}
<Head title={data.player ? `${data.player.username}'s SkyBlock profiles` : 'Invalid player'} />
<Header />
<main>
<h1>
<Username player={data.player} headType="3d" />'s profiles
</h1>
{#if data.profiles && data.profiles.length > 0}
<ul class="profile-list">
{#each data.profiles ?? [] as profile}
<li
class="profile-list-item"
class:profile-list-item-active={profile.uuid === activeProfile?.uuid}
class:profile-list-item-online={profile.uuid === activeProfile?.uuid &&
isActiveProfileOnline}
>
<a
class="profile-name"
href="/player/{data.player?.username}/{profile.name}"
sveltekit:prefetch
>
{profile.name}
</a>
{#if profile.mode !== 'normal'}
<Tooltip>
<span slot="tooltip">
{cleanId(profile.mode)} mode
</span>
<Emoji value={MODE_EMOJIS[profile.mode] ?? DEFAULT_MODE_EMOJI} />
</Tooltip>
{/if}
<span class="profile-members">
{#if (profile.members?.length ?? 0) > 1}
{#each profile.members?.filter(m => !m.left) ?? [] as player}
<span class="member">
<Username
{player}
headType="2d"
hyperlinkToProfile={player.uuid != data.player?.uuid}
/>
</span>
{/each}
{#each profile.members?.filter(m => m.left) ?? [] as player}
<span class="member">
<Username {player} headType="2d" hyperlinkToProfile={profile.uuid} disabled />
</span>
{/each}
{:else}
Solo
{/if}
</span>
</li>
{/each}
</ul>
{:else}
<p>This player has no profiles. <Emoji value="😦" /></p>
{/if}
</main>
<style>
.profile-members {
margin-left: 0.5em;
color: var(--theme-main-text);
}
.profile-members > .member {
margin-right: 0.35em;
}
.profile-list {
font-size: 1.5em;
display: inline-flex;
flex-wrap: wrap;
}
.profile-list-item {
margin-bottom: 0.5em;
color: var(--theme-darker-text);
width: 100%;
}
.profile-list-item-active {
color: #fff;
}
.profile-list-item-online {
color: #0e0;
}
</style>
|